package day01;


/**
 * @author feng
 * @Date 2021/10/13 20:57
 * 存3000,每次存1000，存三次，打印余额
 */
public class RankTest {
    public static void main(String[] args) {
        Account account = new Account(0);
        Customer c1 = new Customer(account);
        Customer c2 = new Customer(account);
        c1.setName("甲");
        c2.setName("乙");
        c1.start();
        c2.start();

    }

}

class Account {
    private double balance;

    public Account(double balance) {
        this.balance = balance;
    }

    //存钱方法
    public synchronized void cunQian(double acm) {
        if (acm > 0) {
            balance += acm;
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        System.out.println(Thread.currentThread().getName()+"账户余额为"+balance);
    }

}

class Customer extends Thread {
    public Customer(Account account){
        this.account = account;
    }
    private double acm;
    private Account account;
    @Override
    public void run() {

        for (int i = 0; i < 3; i++) {
         account.cunQian(1000);
        }

    }
}